
package com.duobao.gongneng;
import java.awt.*;

import javax.swing.*;

import com.duobao.game.DuobaoSwingLaunch;
import com.duobao.server.*;
import com.duobao.uitl.*;
import com.duobao.view.MainPanel;

import java.awt.event.*;

public class Shuijiao extends JPanel implements MouseListener,Runnable{
    DuobaoSwingLaunch game;
    Map heroMap;
    JLabel fanhui;
    JLabel fanhuiyouxi;
    boolean b;//是否睡觉好

    JLabel tishi;
    public Shuijiao(DuobaoSwingLaunch game)
    {
        this.game=game;
        this.heroMap=Maps.getMap(this.game.hero.getLocation());
        GridLayout gl=new GridLayout(16,1,1,1);
        this.setLayout(gl);
        b=false;


        setTishi();
        xiaoguo();
        setFanhui();
    }
    private void xiaoguo()
    {
        this.game.hero.setHP(this.game.hero.getMaxHP());
        this.game.hero.setSP(this.game.hero.getMaxSP());

        if((this.game.hero.getMP()+(int)(this.game.hero.getMaxMP()*(0.2)))>this.game.hero.getMaxMP())
        {
            this.game.hero.setMP(this.game.hero.getMaxMP());
        }else
        {
            this.game.hero.setMP(this.game.hero.getMP()+(int)(this.game.hero.getMaxMP()*(0.2)));
        }
    }
    private void setTishi() {
        tishi=new JLabel("你太累了，倒头就睡着了");
        tishi.setFont(myFont.f2);
        tishi.addMouseListener(this);
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(tishi);
        this.add(jp1);
    }
    private void setFanhui() {
        fanhui=new JLabel();
        fanhui.addMouseListener(this);
        fanhui.setFont(myFont.f2);
        fanhui.setForeground(Color.BLUE);
        fanhui.setText("<html><u>"+"等待"+"</u></html>");
        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(fanhui);
        this.add(jp3);
    }
    private boolean iFText(JLabel jl)
    {
        boolean f=false;
        if(jl==tishi)
        {
            f=true;
        }
        return f;
    }

    public void mouseClicked(MouseEvent e) {
        // TODO Auto-generated method stub
        if(e.getSource()==fanhui)
        {
            if(this.b)
            {
                this.game.setPanel(new MainPanel(this.game,1));
            }
        }
    }
    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
        if(iFText((JLabel)e.getSource()))
        {
            ((JLabel)e.getSource()).setCursor(new Cursor(Cursor.TEXT_CURSOR));
        }
    }
    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub

    }
    public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub

    }
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }
    public void run() {
        // TODO Auto-generated method stub
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        this.b=true;
    }
}
